package basicx.oop.adt


/*-*- coding:utf-8 -*-
* @Author  : ygree
* @Time    : 2021/7/2 0:09
* @Software : IntelliJ IDEA
*/


//密封类，   //枚举--->添加属性-->密封
private sealed class LicenseState {
    //一组类型，继承于密封类
    object Start : LicenseState()//单例,没有属性
    object Wait : LicenseState()
    class Stop(var licenseId: String) : LicenseState() {
        fun update(id: String) {
            licenseId += id
        }
    } //有属性
}

private class SealedDriver(var status: LicenseState) {
    fun checkLicense(): String {
        return when (status) {//需要添加其他分支
            is LicenseState.Start -> "Start"
            is LicenseState.Wait -> "Wait"
            is LicenseState.Stop -> "Stop,param：${(this.status as LicenseState.Stop).licenseId}"
        }
    }
}

private  fun main() {
    val wait = LicenseState.Wait
    println(SealedDriver(wait).checkLicense())
    println("----------------")
    val qualified = LicenseState.Stop("abcd")
    println(qualified.licenseId)
    println(SealedDriver(qualified).checkLicense())
    qualified.update("ddd")
    println(qualified.licenseId)
    println(SealedDriver(qualified).checkLicense())
}


sealed class SealedOpen {
    class Init : SealedOpen()
}